﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Net.Mail;
using System.Xml.Linq;
using System.Threading;
using System.IO;

public partial class mail_send_mail_rejected : System.Web.UI.Page
{
    DataSet ds;
    Profiles p = new Profiles();
    //static DataTable dt;
    int nRowsSelected = 0;
    private static double progress;

    protected void Page_Init(object sender, EventArgs e)
    {
        BindGrid();
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Session["username"] == null && Session["fullname"] == null)
                Response.Redirect("../login/login.aspx");
            else
            {
                lUsername.Text = " " + Session["username"].ToString();
                BindGrid();
                Init_ComboEmail();
                progress=0;
            }

           
        }
    }
    protected void Init_ComboEmail()
    {//recruitment@vas.edu.vn
      //lemy8279: 
        cbEmail.Items.Add("recruitment@vus-etsc.edu.vn");
        cbEmail.Items.Add("recruitment@vas.edu.vn");
        cbEmail.SelectedIndex = 0;

    }
    protected void btnSend_Click(object sender, EventArgs e)
    {

        string fullname, mailto,content_mail;
        int i = 0;
        Utility u = new Utility();
        TimeSpan t=new TimeSpan(0,3,0);
        Recruitment_Information recruitment = new Recruitment_Information();
        Guid id;

        for (i = 0; i < gdListProfilesRejected.VisibleRowCount; i++)
        {
            if (gdListProfilesRejected.Selection.IsRowSelected(i))
            {
                id = (Guid)gdListProfilesRejected.GetRowValues(i, "profile_id");
                fullname = (string)gdListProfilesRejected.GetRowValues(i, "fullname");
                mailto = (string)gdListProfilesRejected.GetRowValues(i, "mail");
                //txtFullName.Text = fullname;
                //txtMailTo.Text = mailto;
                content_mail = txtContentMail.Text.Trim();
                u.SendMail(fullname,cbEmail.SelectedItem.ToString(), mailto, txtSubject.Text.Trim(), content_mail);
                u.Insert_Mail_Send_Info(id, mailto, DateTime.Now
                                        ,content_mail,cbEmail.SelectedItem.ToString() );
                recruitment.Update_Send_Mail_Rejected(id);

                Thread.Sleep(t);
            }
        }

        popupEdit.Show();
         
    }

    protected void BindGrid()
    {
        ds = p.Get_List_Profiles_Rejected();
        gdListProfilesRejected.DataSource = ds;
        gdListProfilesRejected.DataBind();
        gdListProfilesRejected.Columns[1].Visible = false;       
       /*
        if (ds.Tables[0].Rows.Count > 0)
            lTotalItems.Text = ds.Tables[0].Rows.Count.ToString();
        else lTotalItems.Text = "0";*/
         

    }
    protected void gdProfileRejected_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        gdListProfilesRejected.PageIndex = e.NewPageIndex;
        BindGrid();
    }
    protected void gdListProfilesRejected_HtmlRowCreated(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewTableRowEventArgs e)
    {
        e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#f7f7f7';");
        if ((e.VisibleIndex % 2) == 0)
        {
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='white';");
        }
        else
        {
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='white';");
        }
    }

    protected void lnkLogout_Click(object sender, EventArgs e)
    {
        //FormsAuthentication.SignOut();

        Session.Clear();
        Response.Redirect("../login/login.aspx");
    }
  

    protected void timerCallback_Callback(object source, DevExpress.Web.ASPxCallback.CallbackEventArgs e)
    {
        e.Result = progress.ToString();

    }
    protected void mainCallback_Callback(object source, DevExpress.Web.ASPxCallback.CallbackEventArgs e)
    {

        Thread.Sleep(1000);
        progress = 20;
        //e.Result = progress.ToString();
        Thread.Sleep(1500);
        progress = 50;
        //e.Result = progress.ToString();
        Thread.Sleep(1000);
        progress = 70;
        //e.Result = progress.ToString();
        Thread.Sleep(1500);
        progress = 100;


    }

    protected void ASPxCallback1_Callback(object source,DevExpress.Web.ASPxCallback.CallbackEventArgs e)
    {
        int count = 10;
        for (int i = 0; i < count; i++)
        {
            progress = Convert.ToDouble(i) / Convert.ToDouble(count) * 100;
            System.Threading.Thread.Sleep(500);
        }
    }
    protected void ASPxCallback2_Callback(object source,DevExpress.Web.ASPxCallback.CallbackEventArgs e)
    {
        e.Result = progress + "%";
    }

    
}
